package com.ruoyi.project.business.book.controller;

import java.util.List;

import com.ruoyi.project.business.fenlei.service.IFenleiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.book.domain.Book2;
import com.ruoyi.project.business.book.service.IBook2Service;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 图书Controller
 * 
 * @author ZW
 * @date 2022-04-08
 */
@Controller
@RequestMapping("/business/book")
public class Book2Controller extends BaseController
{
    private String prefix = "business/book";

    @Autowired
    private IBook2Service book2Service;


    @RequiresPermissions("business:book:view")
    @GetMapping()
    public String book()
    {
        return prefix + "/book";
    }

    /**
     * 查询图书列表
     */
    @RequiresPermissions("business:book:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Book2 book2)
    {
        startPage();
        List<Book2> list = book2Service.selectBook2List2(book2);
        return getDataTable(list);
    }

    /**
     * 导出图书列表
     */
    @RequiresPermissions("business:book:export")
    @Log(title = "图书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Book2 book2)
    {
        List<Book2> list = book2Service.selectBook2List2(book2);
        ExcelUtil<Book2> util = new ExcelUtil<Book2>(Book2.class);
        return util.exportExcel(list, "图书数据");
    }

    /**
     * 新增图书
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图书
     */
    @RequiresPermissions("business:book:add")
    @Log(title = "图书", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Book2 book2)
    {
        return toAjax(book2Service.insertBook2(book2));
    }

    /**
     * 修改图书
     */
    @RequiresPermissions("business:book:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        Book2 book2 = book2Service.selectBook2ById(id);
        mmap.put("book2", book2);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书
     */
    @RequiresPermissions("business:book:edit")
    @Log(title = "图书", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Book2 book2)
    {
        return toAjax(book2Service.updateBook2(book2));
    }

    /**
     * 删除图书
     */
    @RequiresPermissions("business:book:remove")
    @Log(title = "图书", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(book2Service.deleteBook2ByIds(ids));
    }
}
